home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 2758 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.1 KB  |  65 lines

  1. Newsgroups: comp.lang.c
  2. Path: news.openu.ac.il!news
  3. From: shimoco@mail.tlm.openu.ac.il (Shimon Cohen)
  4. Subject: Re: i = atoi(NULL);
  5. Message-ID: <DLnJpF.ApL@cs.openu.ac.il>
  6. Sender: news@cs.openu.ac.il
  7. Nntp-Posting-Host: shimoco.ppp.openu.ac.il
  8. Organization: Open Univ. of Israel
  9. X-Newsreader: Forte Free Agent 1.0.82
  10. References: <DKwCsG.IGD@cs.openu.ac.il> <96009.103802DSEAMA41@portland.caps.maine.edu> <30F7F466.F43@imsisoft.com>
  11. Date: Tue, 23 Jan 1996 09:03:44 GMT
  12.  
  13.  
  14. Victor Bazarov <vbazarov@imsisoft.com> wrote:
  15.  
  16. >Starduster wrote:
  17. >> 
  18. >> In article <DKwCsG.IGD@cs.openu.ac.il>, shimoco@mail.tlm.openu.ac.il (Shimon
  19. >> Cohen) says:
  20. >> >Hi !
  21. >> >
  22. >> >What ANSI C says about:
  23. >> >i = atoi(NULL);
  24.  
  25. >Actually, nothing specific.
  26. >------------------------------------------------------------------------------
  27. >7.10.1.2
  28. >    int atoi(const char *nptr);
  29. >"The atoi function converts the initial portion of the string pointed by nptr
  30. >to int representation. Except for the behavior on error, it is equivalent to
  31. >    (int)strtol(nptr, (char **)NULL, 10)
  32.  
  33. >7.10.1.5
  34. >    long int strtol(const char *nptr, char **endptr, int base);
  35. >[...]
  36. >  "In other than "C" locale, additional implementation-defined subject sequence
  37. >forms may be accepted.
  38. >   If the subject is empty or does not have the expected form, no conversion is
  39. >performed; ... If no conversion could be performed, zero is returned."
  40. >------------------------------------------------------------------------------
  41. >My advice -- check the pointer for being NULL before passing to atoi().
  42.  
  43. >>    One question: why does it matter? Why would you want to do such a thing?
  44. >> Just curious.
  45.  
  46. >I think Shimon wanted to use atoi with the argument got from another function,
  47. >which returns NULL in case of empty input, errors, or the like.
  48.  
  49. Thats right !
  50. I called  atoi like this:
  51. i = atoi (strtok (input_str, ",");
  52. My compiler (BC4.0) docs says:  "If no conversion could be performed,
  53. zero is returned." . I used this fact and it works fine. but not under
  54. the unix machine of my teacher :-(
  55.  
  56. Shimon Cohen
  57. >>                                             -Darryl
  58.  
  59. >Victor.
  60.  
  61. >-- 
  62. >Signature.
  63.  
  64.  
  65.